#include "stdafx.h"
#include "DataImg.h"
#include <Strsafe.h>
#include "HttpF2.h"

#define	SPACE	0xffffffff

DataImg::DataImg(){
	flg=0;
	len=0;
}
DataImg::~DataImg(void){
}

ushort* DataImg::get(void){
	if(flg==2){
		flg=0;
		data[0]=RPT_DATAIMG;
		uint *d=(uint*)data+1;
		uint *e=(uint*)(bits+len),*s=(uint*)bits+1;
		if(*s==SPACE){
			while(s<e && *s==SPACE)
				s++;
			while(s<e && *s!=SPACE)
				*d++=*s++;
			data[1]=(ubyte*)d-(ubyte*)data;
		}else{
			while(s<e && *s!=SPACE)
				s++;
			while(s<e && *s==SPACE)
				s++;
			while(s<e && *s!=SPACE)
				*d++=*s++;
			s=(uint*)bits+1;
			while(s<e && *s!=SPACE)
				*d++=*s++;
			*d=SPACE;
			data[1]=len;
		}
		if(data[1])
			return data;
	}
	return 0;
}
void DataImg::set(Report* report){
	ushort o=report->ord;
	if(o==len && o<0x7fc4){
		memcpy(bits+o,report->data,60);
		len+=60;
		flg=1;
	}else if(o<len && flg==1)
		flg=2;
}